#include "Maxieye_Spi_Mediator_Contre/Imediator.h"

rclcpp::Logger Base_Mediator::TRACE = rclcpp::get_logger("Base_Mediator");

Base_Mediator::Base_Mediator(const std::string& id, const uint16_t& pos_s_2_m, const size_t& len_s_2_m, const uint16_t& pos_m_2_s, const size_t& len_m_2_s) 
    : its_id_name(id), its_begin_position_soc_2_mcu(pos_s_2_m), its_length_soc_2_mcu(len_s_2_m)
    , its_begin_position_mcu_2_soc(pos_m_2_s), its_length_mcu_2_soc(len_m_2_s)
    , its_soc_2_mcu_data_buffer_df(nullptr), its_mcu_2_soc_data_buffer_df(nullptr)
{
    RCLCPP_INFO_STREAM(TRACE, id << " [soc->mcu:" << its_begin_position_soc_2_mcu << ", size:" << its_length_soc_2_mcu 
                                 << "]; [mcu->soc" << its_begin_position_mcu_2_soc <<", size:" << its_length_mcu_2_soc << "]");
}

void Base_Mediator::register_soc_2_mcu_buffer(Ibuffer_User_Register* user_register)
{
    its_soc_2_mcu_data_buffer_df = user_register->register_out_buffer(its_id_name, Buffer_Id::SOC_OUT_DF, its_begin_position_soc_2_mcu, its_length_soc_2_mcu);
    if(!its_soc_2_mcu_data_buffer_df)
    {
        RCLCPP_ERROR_STREAM(TRACE, "Registers a memory repeatedly");
        abort();
    }
}

void Base_Mediator::register_mcu_2_soc_buffer(Ibuffer_User_Register* user_register)
{
    its_mcu_2_soc_data_buffer_df = user_register->register_in_buffer(its_id_name, Buffer_Id::SOC_IN_DF, its_begin_position_mcu_2_soc, its_length_mcu_2_soc);
    if(!its_mcu_2_soc_data_buffer_df)
    {
        RCLCPP_ERROR_STREAM(TRACE, "Registers a memory repeatedly");
        abort();
    }
}